#pragma once

#include <iostream>
#include <string>
#include <cstdio>
#include <functional>

#include <iostream>
#include "websocketpp_server.hpp"



void serviceIO(int sock)
{
    char buffer[1024];
    while (true)
    {
        ssize_t n = read(sock, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            // 目前我们把读到的数据当成字符串, 截止目前
            buffer[n] = 0;
            std::cout << "recv message: " << buffer << std::endl;
            

            // std::string outbuffer = buffer;
            // outbuffer += " server[echo]";
            std::string outbuffer = "HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Accept: UYDGlYewwjaoDsXEk5Iojg==\r\n\r\n";

            // write(sock, outbuffer.c_str(), outbuffer.size()); // 多路转接
        }
        else if (n == 0)
        {
            // 代表client退出
            // logMessage(NORMAL, "client quit, me too!");
            break;
        }
    }
    // close(sock);
}

class Task
{

public:
    Task()
    {
    }
    Task(websocketpp_server* s, websocketpp::connection_hdl h, server::message_ptr m)
        : server_(s), hdl_(h), message_ptr_(m)
    {
    }

private:
    server::message_ptr message_ptr_;
    websocketpp::connection_hdl hdl_;
    websocketpp_server* server_;
};
